/*
	作者：杨金良
	*/

var urlHead = "/International";
    
var logoutUrl = urlHead + "/admin/exit"
var admincolmanageUrl = urlHead + "/admincolmanage"
var adminmajmanageUrl = urlHead + '/adminmajmanage'
var adminteamanageUrl = urlHead + '/adminteamanage'
var adminstumanageUrl = urlHead + '/adminstumanage'
var admincoumanageUrl = urlHead + '/admincoumanage'
var adminlocmanageUrl = urlHead + '/adminlocmanage'
var adminCourseManageUrl = urlHead + '/adminCourseManage'
var adminScoreManageUrl = urlHead + '/scoreMana'
var adminChangePasswordUrl = urlHead + '/adminUpdate/updateASpwd'
var adminPayManageUrl = urlHead + '/adminPayManage'
var adminVisaManageUrl = urlHead + '/adminVisaManage'
var adminExamManageUrl = urlHead + '/adminExamManage'

$("document").ready(render())


function render(){
    var header_Html = '<div id="header-title">\
                <p><span class="glyphicon glyphicon-home"></span>留学生管理系统</p>\
                </div>\
                <span id="separator"></span>\
                <div id="login-status">\
                    <div id="portrait" class="button-inline" onclick="changePwd()">\
                        <span class="glyphicon glyphicon-user" style="top:2px;font-size: 14px;"></span>管理员<span class="glyphicon glyphicon-triangle-bottom" style="top:2px;font-size: 12px;"></span>\
                    </div>\
                    <a href="' + logoutUrl + '" id="logout" class="button-inline"><span class="glyphicon glyphicon-off" style="top:2px;font-size: 14px;"></span>注销</a>\
                </div>';
    var side_menu_Html = '<div id="mini-logo"></div>\
                <div id="menu">\
                    <ul class="am-list admin-sidebar-list">\
                        <li><a id="admincolmanage" href="' + admincolmanageUrl +'" ><span class="glyphicon glyphicon-globe"></span> 学院管理</a></li>\
                        <li><a id="adminmajmanage" href="' + adminmajmanageUrl +'" ><span class="glyphicon glyphicon-bookmark"></span> 专业管理</a></li>\
                        <li><a id="adminteamanage" href="' + adminteamanageUrl +'" ><span class="glyphicon glyphicon-edit"></span> 教师管理</a></li>\
                        <li><a id="adminstumanage" href="' + adminstumanageUrl +'" ><span class="glyphicon glyphicon-education"></span> 学生管理</a></li>\
                        <li><a id="admincoumanage" href="' + admincoumanageUrl +'" ><span class="glyphicon glyphicon-th-list"></span> 课程库管理</a></li>\
                        <li><a id="adminlocmanage" href="' + adminlocmanageUrl +'" ><span class="glyphicon glyphicon-blackboard"></span> 教室管理</a></li>\
                        <li><a id="adminCourseManage" href="' + adminCourseManageUrl +'" ><span class="glyphicon glyphicon-calendar"></span> 课表管理</a></li>\
                        <li><a id="adminExamManage" href="'+adminExamManageUrl+'" ><span class="glyphicon glyphicon-pencil"></span> 考务管理</a></li>\
                        <li><a id="adminScoreManage" href="' + adminScoreManageUrl +'" ><span class="glyphicon glyphicon-check"></span> 成绩管理</a></li>\
                        <li><a id="adminPayManage" href="'+adminPayManageUrl+'" ><span class="glyphicon glyphicon-usd"></span> 缴费管理</a></li>\
                        <li><a id="adminVisaManage" href="'+adminVisaManageUrl+'" ><span class="glyphicon glyphicon-print"></span> 签证管理</a></li>\
                    </ul>\
                </div>';
    var footer_Html = '<div>Copyright &copy; 2016-2017 浙江工商大学 软件外包创新实验基地 版权所有</div>\
                    <div>地址:浙江省杭州下沙高教园区学正街18号 现代科技教育中心101机房 邮编：310018 联系电话：0571-28008316 13588202450</div><br>'
    $("#header").html(header_Html);
    $("#side-menu").html(side_menu_Html);
    $("#footer").html(footer_Html);
    $(_current_item).addClass("submenu_current_item");
}

function show(str){
    $(str).css("display","block");
}
function hide(str){
    $(str).css("display","none");
}
function changePwd(){
	var pwdHtml ='<div id="pwdPannel" style="position:absolute;z-index:1000;width:100%;height:100%;">\
						<div style="z-index:1100;position:absolute;width:100%;height:100%;">\
							<div class="pannel" style="margin:15% auto 0;padding:10px;width:400px;height:260px;">\
								<div class="close-container">\
							        <a class="close" onclick="$(\'#pwdPannel\').remove()">×</a>\
							    </div>\
							    <table>\
								    <tr>\
										<td>输入原始密码：</td><td><input id="oldPassword" type="password" name="oldPassword" /></td>\
									</tr>\
									<tr>\
										<td>输入新密码：</td><td><input id="newPassword" type="password" name="newPassword"/></td>\
									</tr>\
									<tr>\
										<td>确认新密码：</td><td><input id="rePassword" type="password" name="rePassword"/></td>\
									</tr>\
									<tr>\
										<td id="serverMessage" style="color:red"></td>\
										<td><button onclick="validate()">提交</button></td>\
                                    </tr>\
							    </table>\
							</div>\
						</div>\
						<div style="position:fixed;width:100%;height:100%;background:#555;opacity:0.3;" onclick="$(\'#pwdPannel\').remove()"></div>\
					</div>'
		$("body").prepend(pwdHtml);
}

function validate(){
	if($("#oldPassword").val() == "" || $("#newPassword").val() == "" || $("#rePassword").val() == "")
		alert("密码不能为空");
	else if( $("#newPassword").val() != $("#rePassword").val())
		alert("两次密码不一致");
	else
		$.ajax({
			type:"POST",
	     	url:adminChangePasswordUrl,
	     	dataType:"text",
	     	data:{
	     		oldPassword:$("#oldPassword").val(),
	     		newPassword:$("#newPassword").val(), 		
	     		rePassword:$("#rePassword").val()
	     	},
	     	success:function(data){
                $("#serverMessage").html(data);
                if(data == "success");
                location.href = "/International/upPass"
                }, 
	     	error:function(err){alert("修改密码失败");},
	     });
	return false;
}
var domain = "127.0.0.1"; // 域
/* 设置cookie */
function setCookie(name, value) {
	/* 获取cookie工具 */
	var cookie = $.AMUI.utils.cookie;
	cookie.set(name, value, "/", domain);
}

/* 获得cookie */
function getCookie(name) {
	/* 获取cookie工具 */
	var cookie = $.AMUI.utils.cookie;
	var value = cookie.get(name);
	if (value == "undefined" || value == null || value == "null") {
		return null;
	} else {
		return value;
	}
}

/* 删除cookie */
function removeCookie(name) {
	/* 获取cookie工具 */
	var cookie = $.AMUI.utils.cookie;
	cookie.set(name, null, 0, "/", domain);
}

function removeAllCookie() {
	/* 获取cookie工具 */
	var cookie = $.AMUI.utils.cookie;
	cookie.set("pkCity", null, 0, "/", domain);
	cookie.set("cityName", null, 0, "/", domain);
	cookie.set("pkUser", null, 0, "/", domain);
}

/* 获取cookie有效时间 */
function getCookieTime() {
	end = new Date();
	end = new Date(end.valueOf() + 7 * 24 * 60 * 60 * 1000); // 7天有效
	return end;
}